/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qlvbdq.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import qlvbdq.dconnection.SQLServerConnect;
import qlvbdq.dto.CTBaoCaoTonDTO;

/**
 *
 * @author tuan
 */
public class CTBaoCaoTonKhoDAO {
    
    public ArrayList<CTBaoCaoTonDTO> getCTBaoCaoTonByMaBaoCaoTon(String MaBCTon) throws SQLException {
        ArrayList<CTBaoCaoTonDTO> listCTPDV = new ArrayList<>();
        Object[] objs = { MaBCTon };
        CTBaoCaoTonDTO ctBaoCaoTon = new CTBaoCaoTonDTO();
        ResultSet rs = SQLServerConnect.getInstance().getDataFromStore("GetAllCTBAOCAOTONOfBCTFromDataBase( ? )", objs);
        while (rs.next()) {
            ctBaoCaoTon.setMaBaoCaoTon(rs.getString("MABAOCAOTON"));
            ctBaoCaoTon.setMaSP(rs.getString("MASP"));
            ctBaoCaoTon.setSoLuongBan(rs.getInt("SOLUONGBAN"));
            ctBaoCaoTon.setSoLuongMua(rs.getInt("SOLUONGMUA"));
            ctBaoCaoTon.setTonDauKy(rs.getInt("TONDAUKY"));
            ctBaoCaoTon.setTonCuoiky(rs.getInt("TONCUOIKY"));
            listCTPDV.add(ctBaoCaoTon);
        }
        return listCTPDV;
    }
    
//    public ArrayList<CTBaoCaoTonDTO> getCTBaoCaoTonByMaBaoCaoAndMaSP(String MaBCTon, String MaSP) throws SQLException {
//        ArrayList<CTBaoCaoTonDTO> listCTPDV = new ArrayList<>();
//        Object[] objs = { MaBCTon, MaSP };
//        CTBaoCaoTonDTO ctBaoCaoTon = new CTBaoCaoTonDTO();
//        ResultSet rs = SQLServerConnect.getInstance().getDataFromStore("GetCTBaoCaoTonByMaDVFromDatabase( ?, ? )", objs);
//        while (rs.next()) {
//            ctBaoCaoTon.setMaBaoCaoTon(rs.getString("MABAOCAOTON"));
//            ctBaoCaoTon.setMaSP(rs.getString("MASP"));
//            ctBaoCaoTon.setSoLuongBan(rs.getInt("SOLUONGBAN"));
//            ctBaoCaoTon.setSoLuongMua(rs.getInt("SOLUONGMUA"));
//            ctBaoCaoTon.setTonDauKy(rs.getInt("TONDAUKY"));
//            ctBaoCaoTon.setTonCuoiky(rs.getInt("TONCUOIKY"));
//            listCTPDV.add(ctBaoCaoTon);
//        }
//        return listCTPDV;
//    }
    
    public int insertCTBaoCaoTon(CTBaoCaoTonDTO ctBaoCaoTon) {
        Object[] objs = { ctBaoCaoTon.getMaBaoCaoTon(), ctBaoCaoTon.getMaSP(), ctBaoCaoTon.getTonDauKy(), ctBaoCaoTon.getSoLuongBan(), 
                            ctBaoCaoTon.getSoLuongMua(), ctBaoCaoTon.getTonCuoiky() };
        return SQLServerConnect.getInstance().updateDataToDatabase("InsertCTBAOCAOTONFromDataBase(?, ?, ?, ?, ?, ?)", objs);
    }
    
   //xoa toan bo chi tiet cua BaoCaoTon do
    public int deleteCTBaoCaoTonByMaBaoCao(CTBaoCaoTonDTO ctBaoCaoTon) {
        Object[] objs = { ctBaoCaoTon.getMaBaoCaoTon()};
        return SQLServerConnect.getInstance().updateDataToDatabase("DeleteCTBAOCAOTONOfBCTFromDataBase(?)", objs);
    }
    
    public int deleteCTBaoCaoTonByMaSP(CTBaoCaoTonDTO ctBaoCaoTon) {
        Object[] objs = { ctBaoCaoTon.getMaSP()};
        return SQLServerConnect.getInstance().updateDataToDatabase("DeleteCTBAOCAOTONOfSPFromDataBase(?)", objs);
    }
    
    //delete 1 CT
    public int deleteCTBaoCaoTonByMaPhieuMaDV(CTBaoCaoTonDTO ctBaoCaoTon) {
        Object[] objs = { ctBaoCaoTon.getMaBaoCaoTon(), ctBaoCaoTon.getMaSP()};
        return SQLServerConnect.getInstance().updateDataToDatabase("DeleteCTBAOCAOTONFromDataBase(?, ?)", objs);
    } 
}
